﻿using System;

namespace UniRx.Operators
{
	// Token: 0x0200026E RID: 622
	internal class CombineLatestObservable<T1, T2, T3, T4, T5, TR> : OperatorObservableBase<TR>
	{
		// Token: 0x06000E18 RID: 3608 RVA: 0x00042858 File Offset: 0x00040C58
		public CombineLatestObservable(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, IObservable<T4> source4, IObservable<T5> source5, CombineLatestFunc<T1, T2, T3, T4, T5, TR> resultSelector) : base(source1.IsRequiredSubscribeOnCurrentThread<T1>() || source2.IsRequiredSubscribeOnCurrentThread<T2>() || source3.IsRequiredSubscribeOnCurrentThread<T3>() || source4.IsRequiredSubscribeOnCurrentThread<T4>() || source5.IsRequiredSubscribeOnCurrentThread<T5>())
		{
			this.source1 = source1;
			this.source2 = source2;
			this.source3 = source3;
			this.source4 = source4;
			this.source5 = source5;
			this.resultSelector = resultSelector;
		}

		// Token: 0x06000E19 RID: 3609 RVA: 0x000428D5 File Offset: 0x00040CD5
		protected override IDisposable SubscribeCore(IObserver<TR> observer, IDisposable cancel)
		{
			return new CombineLatestObservable<T1, T2, T3, T4, T5, TR>.CombineLatest(5, this, observer, cancel).Run();
		}

		// Token: 0x04000807 RID: 2055
		private IObservable<T1> source1;

		// Token: 0x04000808 RID: 2056
		private IObservable<T2> source2;

		// Token: 0x04000809 RID: 2057
		private IObservable<T3> source3;

		// Token: 0x0400080A RID: 2058
		private IObservable<T4> source4;

		// Token: 0x0400080B RID: 2059
		private IObservable<T5> source5;

		// Token: 0x0400080C RID: 2060
		private CombineLatestFunc<T1, T2, T3, T4, T5, TR> resultSelector;

		// Token: 0x0200026F RID: 623
		private class CombineLatest : NthCombineLatestObserverBase<TR>
		{
			// Token: 0x06000E1A RID: 3610 RVA: 0x000428E5 File Offset: 0x00040CE5
			public CombineLatest(int length, CombineLatestObservable<T1, T2, T3, T4, T5, TR> parent, IObserver<TR> observer, IDisposable cancel) : base(length, observer, cancel)
			{
				this.parent = parent;
			}

			// Token: 0x06000E1B RID: 3611 RVA: 0x00042904 File Offset: 0x00040D04
			public IDisposable Run()
			{
				this.c1 = new CombineLatestObserver<T1>(this.gate, this, 0);
				this.c2 = new CombineLatestObserver<T2>(this.gate, this, 1);
				this.c3 = new CombineLatestObserver<T3>(this.gate, this, 2);
				this.c4 = new CombineLatestObserver<T4>(this.gate, this, 3);
				this.c5 = new CombineLatestObserver<T5>(this.gate, this, 4);
				IDisposable disposable = this.parent.source1.Subscribe(this.c1);
				IDisposable disposable2 = this.parent.source2.Subscribe(this.c2);
				IDisposable disposable3 = this.parent.source3.Subscribe(this.c3);
				IDisposable disposable4 = this.parent.source4.Subscribe(this.c4);
				IDisposable disposable5 = this.parent.source5.Subscribe(this.c5);
				return StableCompositeDisposable.Create(new IDisposable[]
				{
					disposable,
					disposable2,
					disposable3,
					disposable4,
					disposable5
				});
			}

			// Token: 0x06000E1C RID: 3612 RVA: 0x00042A04 File Offset: 0x00040E04
			public override TR GetResult()
			{
				return this.parent.resultSelector(this.c1.Value, this.c2.Value, this.c3.Value, this.c4.Value, this.c5.Value);
			}

			// Token: 0x06000E1D RID: 3613 RVA: 0x00042A58 File Offset: 0x00040E58
			public override void OnNext(TR value)
			{
				this.observer.OnNext(value);
			}

			// Token: 0x06000E1E RID: 3614 RVA: 0x00042A68 File Offset: 0x00040E68
			public override void OnError(Exception error)
			{
				try
				{
					this.observer.OnError(error);
				}
				finally
				{
					base.Dispose();
				}
			}

			// Token: 0x06000E1F RID: 3615 RVA: 0x00042AA0 File Offset: 0x00040EA0
			public override void OnCompleted()
			{
				try
				{
					this.observer.OnCompleted();
				}
				finally
				{
					base.Dispose();
				}
			}

			// Token: 0x0400080D RID: 2061
			private readonly CombineLatestObservable<T1, T2, T3, T4, T5, TR> parent;

			// Token: 0x0400080E RID: 2062
			private readonly object gate = new object();

			// Token: 0x0400080F RID: 2063
			private CombineLatestObserver<T1> c1;

			// Token: 0x04000810 RID: 2064
			private CombineLatestObserver<T2> c2;

			// Token: 0x04000811 RID: 2065
			private CombineLatestObserver<T3> c3;

			// Token: 0x04000812 RID: 2066
			private CombineLatestObserver<T4> c4;

			// Token: 0x04000813 RID: 2067
			private CombineLatestObserver<T5> c5;
		}
	}
}
